|
In computer science, Kosaraju's algorithm (also known as the Kosaraju–Sharir algorithm) is a linear time algorithm to find the strongly connected components of a directed graph. Aho, Hopcroft and Ullman credit it to an unpublished paper from 1978 by S. Rao Kosaraju. The same algorithm was independently discovered by Micha Sharir and published by him in 1981. It makes use of the fact that the transpose graph (the same graph with the direction of every edge reversed) has exactly the same strongly connected components as the original graph. ==The algorithm== Kosaraju's algorithm works as follows: * Let G be a directed graph and S be an empty stack. * While S does not contain all vertices: * * Choose an arbitrary vertex ''v'' not in S. Perform a depth-first search starting at ''v''. Each time that depth-first search finishes expanding a vertex ''u'', push ''u'' onto S. * Reverse the directions of all arcs to obtain the transpose graph. * While S is nonempty: * * Pop the top vertex ''v'' from S. Perform a depth-first search starting at ''v'' in the transpose graph. The set of visited vertices will give the strongly connected component containing ''v''; record this and remove all these vertices from the graph G and the stack S. Equivalently, breadth-first search (BFS) can be used instead of depth-first search. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Kosaraju's algorithm」の詳細全文を読む スポンサード リンク
|